package 二分查找;
/*
  二分查找----------递归算法
 */
public class TwoFenRecusion {
    public static void main(String[] args) {
        int[] arr = {12,33,45,23,65,48};
        int val = 23;
        int res = bsearch(arr, arr.length, val);
        System.out.println(res);
    }
    public static int bsearch(int[] arr, int n, int val) {
        return bsearchInternally(arr, 0, n - 1, val);

    }
    public static int bsearchInternally(int[] arr, int low, int high, int value) {
        if (low > high) return -1;

        int mid =  low + ((high - low) >> 1);

        if (arr[mid] == value) {
            return mid;

        } else if (arr[mid] < value) {
            return bsearchInternally(arr, mid+1, high, value);

        } else {
            return bsearchInternally(arr, low, mid-1, value);

        }

    }
}
